<template>
    <div class="position-card" :class="{ 'is-active': isActive }" @click="$emit('click')">
        <div class="position-card-header">
            <div class="company-info">
                <el-avatar :size="50" :src="positionData.companyLogo" @click.stop="$emit('company-click')" />
                <div class="company-meta">
                    <h3 class="position-title">{{ positionData.title }}</h3>
                    <span class="company-name" @click.stop="$emit('company-click')">{{
                        positionData.companyName
                    }}</span>
                </div>
            </div>
            <div class="salary">{{ positionData.salary }}</div>
        </div>

        <div class="position-card-body">
            <div class="position-location">
                <el-icon><Location /></el-icon>
                <span>{{ positionData.location }}</span>
            </div>
            <div class="position-tags">
                <el-tag v-for="(tag, index) in positionData.tags" :key="index" size="small" effect="plain">{{
                    tag
                }}</el-tag>
            </div>
        </div>
    </div>
</template>

<script setup>
import { Location } from "@element-plus/icons-vue";

defineProps({
    positionData: {
        type: Object,
        required: true,
    },
    isActive: {
        type: Boolean,
        default: false,
    },
});

defineEmits(["click", "company-click"]);
</script>

<style scoped>
.position-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    cursor: pointer;
    border: 1px solid #e4e7ed;
    transition: all 0.3s ease;
}

.position-card:hover {
    border-color: var(--el-color-primary-light-5);
    box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.1);
}

.position-card.is-active {
    border: 2px solid var(--el-color-primary);
    background-color: var(--el-color-primary-light-9);
}

.position-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.company-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.company-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.position-title {
    font-size: 16px;
    font-weight: 600;
    color: #303133;
    margin: 0;
}

.company-name {
    font-size: 14px;
    color: #606266;
    cursor: pointer;
    transition: color 0.3s;
}

.company-name:hover {
    color: var(--el-color-primary);
    text-decoration: underline;
}

.salary {
    font-size: 18px;
    font-weight: 600;
    color: #f56c6c;
}

.position-card-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.position-location {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #606266;
    font-size: 14px;
}

.position-location .el-icon {
    font-size: 16px;
    color: #909399;
}

.position-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

:deep(.el-tag) {
    border-radius: 4px;
    padding: 0 8px;
    height: 24px;
    line-height: 22px;
    font-size: 12px;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .position-card {
        padding: 16px;
    }

    .position-title {
        font-size: 15px;
    }

    .salary {
        font-size: 16px;
    }

    .company-info {
        gap: 12px;
    }
}
</style>
